package org.falak.ui;

import org.falak.FalakCallerID.R;

import android.app.Activity;
import android.content.Context;
import android.graphics.Point;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class ShowInfo extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.toast_layout);
	}

	public void showInfo(Context context, String info) {
		// Waste some time !
		try {
			Thread.sleep(100);
		} catch (InterruptedException e) {
		}
		// sdfsdfsdfs
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(LAYOUT_INFLATER_SERVICE);
		// LayoutInflater inflater = LayoutInflater.from(ShowInfo.this);
		View layout = inflater.inflate(R.layout.toast_layout, null);
		// (ViewGroup) findViewById(R.id.toast_layout_root));

		ImageView imageCountry = (ImageView) layout.findViewById(R.id.country);
		imageCountry.setImageResource(getCountryFlag(info));

		ImageView imageOperator = (ImageView) layout
				.findViewById(R.id.operator);
		imageOperator.setImageResource(getOperatorImage(info));
		TextView text = (TextView) layout.findViewById(R.id.text);
		text.setText(info);

		Display display = ((WindowManager) context
				.getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
		Point outSize = new Point();
		display.getSize(outSize);

		Toast toast = new Toast(context);
		int yOffset = (outSize.x * 9) / 100;
		toast.setGravity(Gravity.CENTER | Gravity.CENTER, 10, yOffset + 20);
		toast.setDuration(Toast.LENGTH_LONG);
		toast.setView(layout);
		toast.show();
	}

	private int getCountryFlag(String info) {
		if (info.contains("INDIA")) {
			return R.drawable.india;
		}
		if (info.contains("USA")) {
			return R.drawable.usa;
		}
		if (info.contains("UK")) {
			return R.drawable.uk;
		}
		return R.drawable.nope;
	}

	private int getOperatorImage(String info) {
		if (info.contains("TOLL FREE")) {
			return R.drawable.tollfree;
		}
		if (info.contains("AIRTEL")) {
			return R.drawable.airtel;
		}
		if (info.contains("BSNL") || info.contains("CELLONE")) {
			return R.drawable.bsnl;
		}
		if (info.contains("VODAFONE")) {
			return R.drawable.vodafone;
		}
		if (info.contains("IDEA")) {
			return R.drawable.idea;
		}
		if (info.contains("MTS")) {
			return R.drawable.mts;
		}
		if (info.contains("RELIANCE")) {
			return R.drawable.reliance;
		}

		if (info.contains("UNINOR")) {
			return R.drawable.uninor;
		}
		if (info.contains("TATA INDICOM")) {
			return R.drawable.tata;
		}
		if (info.contains("VIRGIN")) {
			return R.drawable.virgin;
		}
		if (info.contains("LOOP")) {
			return R.drawable.loop;
		}
		if (info.contains("DOCOMO")) {
			return R.drawable.docomo;
		}
		if (info.contains("LANDLINE")) {
			return R.drawable.landline;
		}
		return R.drawable.nope;
	}
}
